//
//  ChuanCaiView.m
//  DongChiDaChiProject1
//
//  Created by lanou3g on 15/10/28.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "ChuanCaiView.h"

@interface ChuanCaiView ()
//@property (nonatomic, retain)UILabel *titleLable;
//@property (nonatomic, retain)UILabel *categoryLable;
//@property (nonatomic, retain)UIImageView *imageThumb;// 设置大图
//@property (nonatomic, retain)UILabel *yingyangLable; // 营养
//@property (nonatomic, retain)UILabel *yuanliaoLable;// 原料
@end
@implementation ChuanCaiView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //
        [self subViews];
        
    }
    return self;
}
- (void)subViews
{
    self.contentSize = CGSizeMake(0, kScreenHeight * 1.2);
    
    // 设置标题
    self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(20 * kWidthFitParameter, 20 * kWidthFitParameter, kScreenWidth - 40 * kWidthFitParameter, 50 * kWidthFitParameter)];
    self.titleLable.backgroundColor = [[UIColor orangeColor]colorWithAlphaComponent:0.2];
    self.titleLable.layer.cornerRadius = 8 * kWidthFitParameter;
    self.titleLable.layer.masksToBounds = YES;
    self.titleLable.font = [UIFont systemFontOfSize:24 * kWidthFitParameter];
    [self addSubview:self.titleLable];
    // 设置目录
    self.categoryLable = [[UILabel alloc] initWithFrame:CGRectMake(20 * kWidthFitParameter, self.titleLable.bottom + 5 * kWidthFitParameter, kScreenWidth - 40 * kWidthFitParameter, 30 * kWidthFitParameter)];
    self.categoryLable.numberOfLines = 0;
    //self.categoryLable.backgroundColor = [UIColor greenColor];
    self.categoryLable.font = [UIFont systemFontOfSize:14 * kWidthFitParameter];
    [self addSubview:self.categoryLable];

    // 设置大图
    self.imageThumb = [[UIImageView alloc] initWithFrame:CGRectMake(30 * kWidthFitParameter, self.categoryLable.bottom + 15 * kWidthFitParameter, kScreenWidth - 60 * kWidthFitParameter,(kScreenHeight / 3 - 5) * kWidthFitParameter)];
    self.imageThumb.layer.cornerRadius = 5 * kWidthFitParameter;
    self.imageThumb.layer.masksToBounds = YES;

    self.imageThumb.layer.cornerRadius = 10 * kWidthFitParameter;
    //self.imageThumb.backgroundColor = [UIColor greenColor];
    [self addSubview:self.imageThumb];
    
    // 设置原料
    self.yuanliaoLable = [[UILabel alloc] initWithFrame:CGRectMake(20 * kWidthFitParameter, self.imageThumb.bottom + 15 * kWidthFitParameter, kScreenWidth - 40 * kWidthFitParameter, 70 * kWidthFitParameter)];
    self.yuanliaoLable.numberOfLines = 0;
    self.yuanliaoLable.font = [UIFont systemFontOfSize:16 * kWidthFitParameter];
    //self.yuanliaoLable.backgroundColor = [UIColor greenColor];
    [self addSubview:self.yuanliaoLable];

    // 设置营养
    self.yingyangLable = [[UILabel alloc] initWithFrame:CGRectMake(20 * kWidthFitParameter, self.yuanliaoLable.bottom + 15 * kWidthFitParameter, kScreenWidth - 40 * kWidthFitParameter, kScreenHeight / 3)];
    self.yingyangLable.font = [UIFont systemFontOfSize:16 * kWidthFitParameter];
    self.yingyangLable.textAlignment = NSTextAlignmentNatural;
    //self.yingyangLable.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.yingyangLable];


    
}
// 自定义高度
- (CGFloat)viewWithModel:(EightFoodModel *)model
{
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:16 * kWidthFitParameter] forKey:NSFontAttributeName];
    // 宽度要和 lable 一样大
    CGRect lableFrame = [model.yingyang boundingRectWithSize:CGSizeMake(kScreenWidth - 40 * kWidthFitParameter, 10000000000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return lableFrame.size.height;
}
@end
